
//% color="#FF8C00" iconWidth=50 iconHeight=40
namespace bert_text{


    //% block="初始化模块" blockType="command"
    export function init(parameter: any, block: any) {

        Generator.addImport(`from XEdu.hub import Workflow as wf
import numpy as np
from PCA import *
`)   
    }

    //% block="设置[CLS]识别结果类别[CLASS]" blockType="command"
    //% CLS.shadow="normal" CLS.defl="words"
    //% CLASS.shadow="list" CLASS.defl="'king','queen','apple'"
    export function readcap1(parameter: any, block: any) {
        let cls=parameter.CLS.code;
        let classes=parameter.CLASS.code;
        Generator.addInit('classes_vocabulary',`${cls} = ${classes}
words_valus = ${cls}`)
    }
    //% block="使用路径为[PATH]的工具将[CLS]中的词汇转为词向量" blockType="command"
    //% PATH.shadow="string" PATH.defl="checkpoint"
    //% CLS.shadow="normal" CLS.defl="words"
    export function readcapq(parameter: any, block: any) {
        let path=parameter.PATH.code;
        let cls=parameter.CLS.code;
        Generator.addCode(`txt_emb = wf(task='embedding_text',download_path=${path})
txt_embeddings = txt_emb.inference(data=${cls})
# 将词向量转换为numpy数组
vectors = np.array(txt_embeddings)
data_dict = {word: vector for word, vector in zip(words_valus, vectors)}`)
    }
        //% block="---" blockType="tag"
        export function initmodel() {}
    //% block="获取全部词的词向量" blockType="reporter"
    export function readcap1a1(parameter: any, block: any) {
        Generator.addCode(`vectors`)
    }

    //% block="获取第[NUM]个的词向量" blockType="reporter"
    //% NUM.shadow="number" NUM.defl=1

    export function readcap1a(parameter: any, block: any) {
        let num=parameter.NUM.code;

        Generator.addCode(`vectors[${num} - 1]`)
    }
        //% block="---" blockType="tag"
        export function initmodel1() {}
    //% block="获取全部词向量的可视化显示[PATH]" blockType="command"
    //% PATH.shadow="string" PATH.defl="word_vectors.html"
    export function readcap1b(parameter: any, block: any) {
        let path=parameter.PATH.code;
        Generator.addCode(`
visualize_data_3d_interactive_v1(data_dict, ${path})`)
    }
    //% block="计算全部词向量之间的相似度并输出" blockType="reporter"
    export function readcap2(parameter: any, block: any) {
        Generator.addCode(`run_ss(vectors,words_valus)`)
        }
 
}